/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.s2aei.controller;

import com.s2aei.busisnes.AlunoBO;
import com.s2aei.model.Aluno;
import com.s2aei.model.Usuario;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author Christian
 */
@ManagedBean
@ViewScoped
public class AlunoController implements Serializable {

    /**
     * Creates a new instance of AlunoController
     */
    private Aluno aluno = new Aluno();
    private Usuario user = new Usuario();
    private List alunosList = new ArrayList();
    private List userList = new ArrayList();

    public List getUserList() {
        return userList;
    }

    public void setUserList(List userList) {
        this.userList = userList;
    }
    
    public AlunoController() {
        alunosList = new AlunoBO().listaAlunos();
    }

    public Aluno getAluno() {
        return aluno;
    }

    public void setAluno(Aluno aluno) {
        this.aluno = aluno;
    }

    public Usuario getUser() {
        return user;
    }

    public void setUser(Usuario user) {
        this.user = user;
    }

    public List getAlunosList() {
        return alunosList;
    }

    public void setAlunosList(List alunosList) {
        this.alunosList = alunosList;
    }
    
    public void criaAluno(){
        AlunoBO alunoNegocio = new AlunoBO();
        alunoNegocio.criarAluno(user, aluno);
        
        //Atualiza os conroles web
        aluno.setUsuario(user);
        alunosList.add(aluno);
        userList.add(user);
        aluno = new Aluno();
        user = new Usuario();
    }
    
    public void editaAluno(){
        user = aluno.getUsuario();
        AlunoBO alunoNegocio = new AlunoBO();
        alunoNegocio.alteraAluno(user, aluno);
    }
    
    public void deletaAluno(){
        AlunoBO alunoNegocio = new AlunoBO();
        alunoNegocio.removeAluno(user, aluno);
        alunosList = alunoNegocio.listaAlunos();
    }
    
}
